<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>jsx 语法</title>
  <style>
    .bg-yellow {
      background-color: yellow;
    }
  </style>
</head>
<body>
  <div id="container"></div>

  <script src="../js/react.development.js"></script>
  <script src="../js/react-dom.development.js"></script>
  <script src="../js/babel.min.js"></script>
  <script type="text/babel">
    /*
      语法规则：
        1. 定义虚拟DOM时，不能写引号，写引号就成了字符串
        2. 标签中混入JS表达式时要用 `{}`
        3. 样式的类名指定不要用class，要用 className，因为 class 是 es6 的关键字
        4. 内联样式要用 `style={{key: value}}` 的形式去写
        5. 虚拟 DOM 必须只能有一个根标签
        6. 标签必须闭合
        7. 标签首字母
          1. 若小写字母开头，则将该标签转为html中同名的标签，若html中无该标签对应的同名元素，则报错
          2. 若大写字母开头，react就去渲染对应的组件，若组件没有定义，则报错
    */
    const myId = 'MycOntAinEr'
    const myData = 'HeLlo'

    function formatName(user) {
      return user.firstName + ' ' + user.lastName
    }
    const user = {
      firstName: 'Harper',
      lastName: 'Perez'
    }

    const vDom = (
      <div>
        <h2 className="bg-yellow" id={myId}>
          <span style={{fontSize: '28px', color: '#000' }}>{myData}</span>
        </h2>
        <h2 className="bg-yellow" id={myId.toLowerCase()}>
          <span style={{fontSize: '28px', color: '#000' }}>{myData}</span>
        </h2>

        <div>
          { formatName(user) }
        </div>
      </div>
    )
    ReactDOM.render(vDom, document.getElementById('container'))
  </script>



  <div id="root"></div>
  <script type="text/babel">
    const data = [ 'Angular', 'React', 'Vue' ]
    const dom = (
      <div>
        <h1>前端js框架列表</h1>
        <ul>
          {
            data.map(d => <li key={d}>{d}</li>)
          }
        </ul>
      </div>
    )
    ReactDOM.render(dom, document.getElementById('root'))
  </script>
</body>
</html>